package com.hbase.demo;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Test;

import java.io.IOException;

/**
 * =================================
 * <p>
 * Created by cjj on 18-10-12.
 * <p>
 * 描述: HBase 基本操作
 */

public class HBaseDao {


    public static void main(String[] args) throws IOException {

        Configuration conf = HBaseConfiguration.create();

        conf.set("hbase.zookeeper.quorum","cj.sun.hadoop:2181");

        HBaseAdmin admin = new HBaseAdmin(conf);

        TableName name = TableName.valueOf("girl");

        HTableDescriptor desc = new HTableDescriptor(name);

        HColumnDescriptor base_info = new HColumnDescriptor("base_info");
        HColumnDescriptor extra_info = new HColumnDescriptor("extra_info");

        base_info.setMaxVersions(3);

        //desc.addFamily(base_info);
        //desc.addFamily(extra_info);

        admin.addColumn("girl",extra_info);

    }

    @Test
    public void add() throws IOException {
        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum","cj.sun.hadoop:2181");

        HTable girl = new HTable(conf, "girl");

        //新建一个数据 必须给一个序号
        Put rk001 = new Put(Bytes.toBytes("rk001"));

        rk001.add(Bytes.toBytes("base_info"),Bytes.toBytes("name"),Bytes.toBytes("tangyan"));
        rk001.add(Bytes.toBytes("base_info"),Bytes.toBytes("age"),Bytes.toBytes(8));
        rk001.add(Bytes.toBytes("extra_info"),Bytes.toBytes("tail"),Bytes.toBytes("chengshi"));


        girl.put(rk001);

    }
    @Test
    public void get(){

    }
    @Test
    public void update(){

    }
    @Test
    public void delete(){

    }




}
